package com.qianli.user.facade.impl.quota;

import com.fqgj.common.api.Response;
import com.qianli.user.application.UserQuotaApplication;
import com.qianli.user.facade.UserServiceFacade;
import com.qianli.user.facade.quota.UserQuotaServiceFacade;
import com.qianli.user.ro.UserStateCode;
import com.qianli.user.ro.query.UserQuotaQueryRO;
import com.qianli.user.ro.quota.UserQuotaRO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * name:用户额度
 * auth:ting.li@qianli-inc.com
 * date:2018/1/3 20:13
 * version: v1.0.0
 **/
@Service("userQuotaServiceFacade")
public class UserQuotaServiceFacadeImpl implements UserQuotaServiceFacade{

    private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceFacade.class);
    @Autowired
    private UserQuotaApplication userQuotaApplication;

    /**
     * 评估额度
     * @param queryRO
     * @return
     */
    @Override
    public Response<Boolean> evaluateQuota(UserQuotaQueryRO queryRO) {
        if(null == queryRO ){
//            LOGGER.info("UserQuotaServiceFacade.evaluateQuota param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"Param can not be null");
        }
        if(null == queryRO.getUserCode() ){
//            LOGGER.info("UserQuotaServiceFacade.evaluateQuota param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"参数userCode不能为空");
        }
        if(null == queryRO.getCategoryCode() ){
            LOGGER.info("UserQuotaServiceFacade.evaluateQuota param categoryCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"参数categoryCode不能为空");
        }
        Response<Boolean> response = userQuotaApplication.evaluateQuota(queryRO);
        return response;
    }

    /**
     * 保存额度
     * @param userQuota
     * @return
     */
    @Override
    public Response<UserQuotaRO> saveQuota(UserQuotaRO userQuota) {
        if(null == userQuota ){
            LOGGER.info("UserQuotaServiceFacade.saveQuota param can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"参数不能为空");
        }
        if(null == userQuota.getUserCode() ){
            LOGGER.info("UserQuotaServiceFacade.saveQuota param userCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"参数userCode不能为空");
        }
        if(null == userQuota.getCategoryCode() ){
            LOGGER.info("UserQuotaServiceFacade.saveQuota param categoryCode can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"参数categoryCode不能为空");
        }
        if(null == userQuota.getQuota()){
            LOGGER.info("UserQuotaServiceFacade.saveQuota param quota can not be null");
            return Response.error(UserStateCode.PARAMETER_LACK,"参数quota不能为空");
        }
        Response<UserQuotaRO> response = userQuotaApplication.saveQuota(userQuota);
        return response;
    }
}
